import java.util.ArrayList;

public class HW_7_isSushuAndHuiwen {
    public static void main(String[] args) {
        int count=0;
        for (int i = 1; i <= 1000; i++) {
            if (isSushuAndHuiwen(i)){
                System.out.print(i+" ");
                count++;
            }
            if (count==10){
                System.out.println();
                count=0;
            }
        }
    }
    public static boolean isSushuAndHuiwen(int num){
        int flag1=0;
        int flag2=0;
        for (int i = 0; i <= num/2; i++) {
            if (i%num==0){
                flag1=1;
            }
        }
        ArrayList<Integer> list = new ArrayList<>();
        while (num > 0) {
            list.add(num % 10);
            num /= 10;
        }
        int left = 0;
        int right = list.size() - 1;
        while (left < right) {
            if (!list.get(left).equals(list.get(right))) {
                flag2=1;
            }
            left++;
            right--;
        }
        if (flag1==1 && flag2==0){
            return true;
        }
        return false;
    }
}
